<%
simple_type = filetype.split('/')[0].lower()
file_short_src = 'http://p.hydra.ws/' + short_key
file_external_src = '/api/file/' + short_key
stylesheets = tuple(('pygments.css', ))

# Opengraph & twitter cards
if simple_type == 'image':
    og_image = '/api/file/' + key
    card_type = 'photo'
end  # (if)
%>
% include(top)

<div class="pure-g">
	<div class="pure-u-1">
		<h1 class="center">{{title}}</h1>
	</div>
<div class="pure-u-1 pure-u-lg-1-8"></div>
<div class="pure-u-1 pure-u-lg-3-4 content">
	<div class="pure-u-1 center boxed" id="infobox">
		<p>By {{user}} {{time}}. \\
% if filename:
 Filename: {{filename}} \\
% end
 Mimetype: {{filetype}}</p><p>\\
% if int(expires) == 0:
Expires: Never
% else:
%     import datetime as dt
%     expires_dt = dt.datetime.fromtimestamp(0) + dt.timedelta(seconds=int(expires))
%     expires_str = expires_dt.strftime('%D %H:%M:%S')
Expires: <span id="expires">{{expires_str}}</span>
% end
; Size:{{filesize}} bytes; Views:{{views}} \\
% if user == username or user_is_admin:
<a href="/delete/{{short_key}}">Delete Paste</a> \\
% end
<a href="{{file_external_src}}" download="{{title}}" type="{{filetype}}">Download Paste</a></p>
<p>Share URL:<input type="text" id="share-url" value="http://paste.hydra.ws/p/{{short_key}}" /> &nbsp;Short URL: <input type="text" id="short-url" value="{{file_short_src}}" /> &nbsp;</p></div>
	<div id="paste" class="pure-u-1">
<%
import fixmimetypes

# Try and determine whether or not paste is supported by pygments
lex = fixmimetypes.get_lexer(filetype)

if lex:
    from pygments import highlight
    from pygments.formatters import HtmlFormatter
    # from pygments.styles import pastie  # No longer used b/c we use our own CSS

    with open(file_internal_src, 'rt') as file_obj:
        #formatter = HtmlFormatter(linenos = True, style=pastie, cssclass='pastecode', full=True)
        formatter = HtmlFormatter(linenos=True, nowrap=False, cssclass='pastecode')
        formatted_text = highlight(file_obj.read(), lex, formatter)
    end  # (with)
end  # (if)

# workaround for .webm because .webm is not detected correctly with pymagic
if filetype.lower() == 'application/octet-stream' and '.webm' in filename:
    simple_type = 'video'
    filetype = 'video/webm'
end # (if)
%>
% if lex:
{{!formatted_text}}
% elif simple_type == 'image':
		<div class="center">
			<img src="{{file_external_src}}" alt="{{title}}" />
		</div>\\
% elif simple_type == 'video':
		<div class="center">
			<video src="{{file_external_src}}" type="{{filetype}}" preload controls>
				<h2>Sorry, your old-ass browser doesn't support <code>video</code> tags.</h2>
				<p>How about <a href="http://browsehappy.com/">updating?</a></p>
			</video>
		</div>\\
% elif simple_type == 'audio':
		<div class="center">
			<audio src="{{file_external_src}}" type="{{filetype}}" preload controls>
				<h2>Sorry, your old-ass browser doesn't support <code>audio</code> tags.</h2>
				<p>How about <a href="http://browsehappy.com/">updating?</a></p>
			</audio>
		</div>\\
% elif filetype == 'application/pdf':
		<div class="center">
			<object id="pasteobj" class="pure-u-1" data="{{file_external_src}}" type="application/pdf">
				<p>It looks like you don't have a plugin installed to view this paste. Try clicking <a href="{{file_external_src}}">this link</a> instead.</p>
			</object>
		</div>\\
% end  # (if)

	</div>
	</div>
	<div class="pure-u-1 pure-u-lg-1-8"></div>
</div>
<script type="text/javascript">
document.getElementById("share-url").select();
</script>

% include(bottom)
